package thinkingInJava.containers;
// page 487 LinkedHashMap 可保证元素插入时的顺序又兼顾查询效率，另外还可以（设置）把最近未使用元素放到顺序的前面
//: containers/LinkedHashMapDemo.java
//What you can do with a LinkedHashMap.
import java.util.*;
import static thinkingInJava.YTool.YPrint.*;

public class LinkedHashMapDemo {
public static void main(String[] args) {
 LinkedHashMap<Integer,String> linkedMap =
   new LinkedHashMap<Integer,String>(
     new CountingMapData(9));
 print(linkedMap);
 // Least-recently-used order:
 linkedMap =
   new LinkedHashMap<Integer,String>(16, 0.75f, true);	// true: 最近访问顺序
 linkedMap.putAll(new CountingMapData(9));
 print(linkedMap);
 for(int i = 0; i < 6; i++) // Cause accesses:
   linkedMap.get(i);
 print(linkedMap);
 linkedMap.get(0);
 print(linkedMap);
}
} /* Output:
{0=A0, 1=B0, 2=C0, 3=D0, 4=E0, 5=F0, 6=G0, 7=H0, 8=I0}
{0=A0, 1=B0, 2=C0, 3=D0, 4=E0, 5=F0, 6=G0, 7=H0, 8=I0}
{6=G0, 7=H0, 8=I0, 0=A0, 1=B0, 2=C0, 3=D0, 4=E0, 5=F0}
{6=G0, 7=H0, 8=I0, 1=B0, 2=C0, 3=D0, 4=E0, 5=F0, 0=A0}
*///:~

